package com.lcxw.hxzbadmin.controller.richlevelcontroller;

import com.alibaba.fastjson.JSONObject;
import com.lcxw.hxzbcommon.entity.ErrorCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbcommon.common.ObsUtil;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("admin/richLevel")
public class RichLevelPicController {

    private ObsUtil obsUtil = new ObsUtil();

    @PostMapping("/pic/upload")
    public Response uploadRichLevelPic(@RequestBody JSONObject requestParams)  {
        String name = requestParams.getString("name");
        String picName = requestParams.getString("picName");
        String imgOrigin = requestParams.getString("pic");
        String suffix = picName.substring(picName.lastIndexOf("."));
        String imgName = "richLevelPic/" + name + "_richLevel"+suffix;
        String picUrl;
        try {
            picUrl = obsUtil.uploadPic(imgName,imgOrigin);
        } catch (Exception e) {
            return Response.common(log,"上传富豪等级图片失败", ErrorCode.EXTERNAL_ERROR,"上传富豪等级图片失败",null);
        }

        return Response.ok(picUrl);
    }

}
